#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"

int main( int argc, char *argv[] )
{
	int i, fd[100];
	if ( argc <= 1 )
	{
		printf( 1, "no argc\n" );
		exit();
	}
	int filenum = atoi( argv[1] );
	if ( filenum > 99 )
	{
		printf( 1, "to mach testfile\n" );
		exit();
	}

	printf( 1, "------test large file read------\n" );

	int	start, end;
	char	str[512];
	char	filename[100][3];
	for ( i = 0; i < filenum; i++ )
	{
		filename[i][0]	= i / 10 + '0';
		filename[i][1]	= i % 10 + '0';
		filename[i][2]	= '\0';
	}

	for ( i = 0; i < filenum; i++ )
	{
		if ( (fd[i] = open( filename[i], O_RDONLY ) ) < 0 )
		{
			printf( 1, "test: cannot open %s\n", filename[i] );
			exit();
		}
	}

	start = uptime();

	for ( i = 0; i < filenum; i++ )
	{
    int rand = uptime()%filenum;
		for ( int ii = 0; ii < 130; ii++ )
			read( fd[rand], str, 512 );
		/* sleep(100); */
	}

	end = uptime();

	printf( 1, "read time total: %d, avg: %d\n", end - start, (end - start) / filenum );

	for ( i = 0; i < filenum; i++ )
	{
		close( fd[i] );
	}
  
	exit();
}